



public class AssignStmt extends Statement {

	String id;
	Expression expession;

	public AssignStmt(String id, Expression expession) {
		this.expession = expession;
		this.id = id;
	}

	public void check() throws SemanticException {
		SymbolTable table = SymbolTable.getInstance();
		// If variable not declared or declared but not as variable
		if (!table.contains(id) || table.contains(id)
				&& table.get(id).category != Entry.VARIABLE)
			throw new SemanticException(
					"Variable not declared before assignment: " + id);
		expession.check();
		int expressionType = expession.checkType();
		int varType = table.get(id).type;
		if (varType != expressionType)
			throw new SemanticException(
					"Assignment expression must be on same types");
		// check for same type
	}

	public String toString() {
		String ret = "AssignStmt " + id + "\n";
		String s = expession.toString();
		for (String st : s.split("\n"))
			ret += "| " + st + "\n";
		return ret;
	}
}
